import Context from './myredux';
import React,{ useReducer } from 'react';
/*创建一个全局的Reducer*/
const initState = {
    name:'xin',
    age:10,
    someMes:'some Message...'
};
function reducer(state,action){
  console.log('action',action)
 switch(action.type){
  case 'increment':
      return {...state, age:action.payload}
  case 'setState' : 
    return {...state,...action.payload}
  
  default:{state}
}
}

const Provider = ({children})=>{
    const [state,dispatch] = useReducer(reducer,initState);

return (
   <Context.Provider value={{state,dispatch}}>
      {children}
   </Context.Provider>
)

};
export default Provider;